Skip to content

Conversation

sequencerr
Copy link

diff: main...sequencerr:json-server:feature/add-middleware
credit: https://github.com/typicode/json-server/pull/1625/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5

restoring readme from history: https://github.com/typicode/json-server/blob/v0/README.md?plain=1#L379-L407

json-server/README.md

Lines 379 to 407 in baf0aee

### Add middlewares
You can add your middlewares from the CLI using `--middlewares` option:
```js
// hello.js
module.exports = (req, res, next) => {
res.header('X-Hello', 'World')
next()
}
```
```bash
json-server db.json --middlewares ./hello.js
json-server db.json --middlewares ./first.js ./second.js
```
### CLI usage
```
json-server [options] <source>
Options:
--config, -c Path to config file [default: "json-server.json"]
--port, -p Set port [default: 3000]
--host, -H Set host [default: "localhost"]
--watch, -w Watch file(s) [boolean]
--routes, -r Path to routes file
--middlewares, -m Paths to middleware files [array]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants